
/*
 * GreenhouseControlsUI class
 * This class produces the Graphical User Interface which is used to control a
 * GreenhouseControls object. Outputs from the GreenhouseControls are displayed
 * through this GUI.
 * 
 * James Zhang
 * ID: 3069886
 * July 17, 2012
 */
import javax.swing.*;
import java.io.*;
import java.util.ArrayList;
import javax.swing.filechooser.FileNameExtensionFilter;

public class GreenhouseControlsUI extends javax.swing.JFrame
{
    //Path of the event file
    protected String filepath;
    //Boolean state if GreenhouseControls is running
    protected boolean busy;
    //Number of windows open
    private static int openWindows = 1;
    //Reference to the GreenhouseControls object
    protected GreenhouseControls gc;

    /**
     * Creates new form GreenhouseControlsUI
     */
    public GreenhouseControlsUI()
    {
        //Creates the GUI
        initComponents();
        //GreenhouseControls is not running
        busy = false;
        //Sets all buttons to disabled at first
        jButton1.setEnabled( false );
        jButton2.setEnabled( false );
        jButton3.setEnabled( false );
        jButton4.setEnabled( false );
        jButton5.setEnabled( false );
        jMenuItem6.setEnabled( false );
        jMenuItem7.setEnabled( false );
        jMenuItem8.setEnabled( false );
        jMenuItem9.setEnabled( false );
        jMenuItem10.setEnabled( false );

        jTextArea1.setText( "Please select an Event file or Restore object.\n" );
        //Default close operation
        setDefaultCloseOperation( DO_NOTHING_ON_CLOSE );
        //Adds the popup menu
        jPanel1.setComponentPopupMenu( jPopupMenu1 );
        //Overrides the close button
        addWindowListener( new java.awt.event.WindowAdapter()
        {
            public @Override
            void windowClosing( java.awt.event.WindowEvent evt )
            {
                //When GreenhouseControls is running, confirm exit
                close();
            }
        } );
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor. -By NetBeans
     */
    @SuppressWarnings( "unchecked" )
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenuItem10 = new javax.swing.JMenuItem();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();

        jMenuItem6.setText("Start");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jPopupMenu1.add(jMenuItem6);

        jMenuItem7.setText("Restart");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jPopupMenu1.add(jMenuItem7);

        jMenuItem8.setText("Suspend");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jPopupMenu1.add(jMenuItem8);

        jMenuItem9.setText("Resume");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        jPopupMenu1.add(jMenuItem9);

        jMenuItem10.setText("Terminate");
        jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem10ActionPerformed(evt);
            }
        });
        jPopupMenu1.add(jMenuItem10);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setMaximumSize(new java.awt.Dimension(250, 250));
        jPanel1.setMinimumSize(new java.awt.Dimension(50, 50));

        jButton1.setText("Start");
        jButton1.setMaximumSize(new java.awt.Dimension(75, 23));
        jButton1.setMinimumSize(new java.awt.Dimension(75, 23));
        jButton1.setPreferredSize(new java.awt.Dimension(75, 23));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Suspend");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        jButton3.setText("Resume");
        jButton3.setMaximumSize(new java.awt.Dimension(75, 23));
        jButton3.setMinimumSize(new java.awt.Dimension(75, 23));
        jButton3.setPreferredSize(new java.awt.Dimension(75, 23));
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });

        jButton4.setText("Restart");
        jButton4.setMaximumSize(new java.awt.Dimension(75, 23));
        jButton4.setMinimumSize(new java.awt.Dimension(75, 23));
        jButton4.setPreferredSize(new java.awt.Dimension(75, 23));
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton4MouseClicked(evt);
            }
        });

        jButton5.setText("Terminate");
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton5MouseClicked(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("[ Current loaded file ]");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(47, 47, 47)
                                .addComponent(jButton5)))
                        .addGap(14, 14, 14))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(7, 7, 7)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton5))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jMenu1.setText("File");

        jMenuItem2.setMnemonic( 'N' );
        jMenuItem2.setText("Open New Window");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem1.setMnemonic( 'O' );
        jMenuItem1.setText("Open Event File");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem3.setMnemonic( 'R' );
        jMenuItem3.setText("Open Restore File");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem4.setMnemonic( 'C' );
        jMenuItem4.setText("Close Current Window");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuItem5.setMnemonic( 'X' );
        jMenuItem5.setText("Exit");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem5);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    //When Suspend button is clicked
    private void jButton2MouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jButton2MouseClicked
    {//GEN-HEADEREND:event_jButton2MouseClicked
        gc.suspendAll();
        jButton2.setEnabled( false );
        jMenuItem8.setEnabled( false );
        jButton3.setEnabled( true );
        jMenuItem9.setEnabled( true );
        busy = true;
    }//GEN-LAST:event_jButton2MouseClicked

    //When Resume button is clicked
    private void jButton3MouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jButton3MouseClicked
    {//GEN-HEADEREND:event_jButton3MouseClicked
        gc.resumeAll();
        jButton2.setEnabled( true );
        jMenuItem8.setEnabled( true );
        jButton3.setEnabled( false );
        jMenuItem9.setEnabled( false );
        busy = true;
    }//GEN-LAST:event_jButton3MouseClicked

    //When Restart button is clicked
    private void jButton4MouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jButton4MouseClicked
    {//GEN-HEADEREND:event_jButton4MouseClicked
        jTextArea1.setText( "" );
        gc.stopAll();
        busy = false;
        gc.threadList = new ArrayList<Thread>();
        gc.eventList = new ArrayList<Event>();
        Restart res = new Restart( gc, 0, filepath );
        busy = true;
        jButton2.setEnabled( true );
        jMenuItem8.setEnabled( true );
        jButton5.setEnabled( true );
        jMenuItem10.setEnabled( true );
        res.thread.start();
    }//GEN-LAST:event_jButton4MouseClicked

    //When File -> Open Event File is clicked
    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jMenuItem1ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem1ActionPerformed
        final JFileChooser fc = new JFileChooser();
        fc.setFileFilter( new FileNameExtensionFilter( "Event File", "txt" ) );
        int returnPath = fc.showOpenDialog( jLabel1 );

        if ( returnPath == JFileChooser.APPROVE_OPTION )
        {
            File file = fc.getSelectedFile();
            filepath = file.getAbsolutePath();
            jLabel1.setText( filepath );
            jButton1.setEnabled( true );
            jMenuItem6.setEnabled( true );
            if ( gc == null )
            {
                jTextArea1.append( "Please start a new Green house.\n" );
            } else
            {
                jButton4.setEnabled( true );
                jMenuItem7.setEnabled( true );
            }
        } else
        {
            gc.gui.jTextArea1.append( "Open command cancelled by user." );
        }
        busy = false;
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    //When Terminate button is clicked
    private void jButton5MouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jButton5MouseClicked
    {//GEN-HEADEREND:event_jButton5MouseClicked
        gc.suspendAll();
        busy = false;
        long time = Long.parseLong( JOptionPane.showInputDialog( "Please specify delay of new Terminate event in milliseconds:" ) );
        Terminate te = new Terminate( gc, time );
        gc.eventList.add( te );
        gc.threadList.add( te.thread );
        gc.resumeAll();
        te.thread.start();
    }//GEN-LAST:event_jButton5MouseClicked

    //When Start button is clicked
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
        jButton1.setEnabled( false );
        jMenuItem6.setEnabled( false );
        jButton4.setEnabled( true );
        jMenuItem7.setEnabled( true );
        gc = new GreenhouseControls( this );
        jTextArea1.append( "New Green house started.\n" );
    }//GEN-LAST:event_jButton1ActionPerformed

    //When File -> New Window button is clicked
    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jMenuItem2ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem2ActionPerformed
        GreenhouseControlsUI gui2 = new GreenhouseControlsUI();
        gui2.setLocationRelativeTo( null );
        gui2.setVisible( true );
        openWindows += 1;
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    //When File -> Open Restore button is clicked
    private void jMenuItem3ActionPerformed( java.awt.event.ActionEvent evt )//GEN-FIRST:event_jMenuItem3ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem3ActionPerformed
        jTextArea1.setText( "" );
        jButton1.setEnabled( false );
        jButton2.setEnabled( false );
        jButton3.setEnabled( false );
        jButton4.setEnabled( false );
        jButton5.setEnabled( false );
        jMenuItem6.setEnabled( false );
        jMenuItem7.setEnabled( false );
        jMenuItem8.setEnabled( false );
        jMenuItem9.setEnabled( false );
        jMenuItem10.setEnabled( false );
        final JFileChooser fc = new JFileChooser();
        fc.setFileFilter( new FileNameExtensionFilter( "Dump File", "out" ) );
        int returnPath = fc.showOpenDialog( jLabel1 );

        if ( returnPath == JFileChooser.APPROVE_OPTION )
        {
            File file = fc.getSelectedFile();
            //This is where a real application would open the file.
            filepath = file.getAbsolutePath();
            jLabel1.setText( filepath );
            busy = true;
            jButton4.setEnabled( false );
            jMenuItem7.setEnabled( false );
            new Restore( filepath, this );
        } else
        {
            jTextArea1.append( "Open command cancelled by user." );
        }
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    //When File -> Close window button is clicked
    private void jMenuItem4ActionPerformed( java.awt.event.ActionEvent evt )//GEN-FIRST:event_jMenuItem4ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem4ActionPerformed
        close();
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    //When File -> Exit button is clicked
    private void jMenuItem5ActionPerformed( java.awt.event.ActionEvent evt )//GEN-FIRST:event_jMenuItem5ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem5ActionPerformed
        close();
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    //When Popmenu Start button is clicked
    private void jMenuItem6ActionPerformed( java.awt.event.ActionEvent evt )//GEN-FIRST:event_jMenuItem6ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem6ActionPerformed
        jTextArea1.setText( "" );
        jButton1.setEnabled( false );
        jMenuItem6.setEnabled( false );
        jButton4.setEnabled( true );
        jMenuItem7.setEnabled( true );
        gc = new GreenhouseControls( this );
        jTextArea1.append( "New Green house started.\n" );
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    //When Popmenu Restart button is clicked
    private void jMenuItem7ActionPerformed( java.awt.event.ActionEvent evt )//GEN-FIRST:event_jMenuItem7ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem7ActionPerformed
        jTextArea1.setText( "" );
        gc.stopAll();
        busy = false;
        gc.threadList = new ArrayList<Thread>();
        gc.eventList = new ArrayList<Event>();
        Restart res = new Restart( gc, 0, filepath );
        busy = true;
        jButton2.setEnabled( true );
        jMenuItem8.setEnabled( true );
        jButton5.setEnabled( true );
        jMenuItem10.setEnabled( true );
        res.thread.start();
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    //When Popmenu Suspend button is clicked
    private void jMenuItem8ActionPerformed( java.awt.event.ActionEvent evt )//GEN-FIRST:event_jMenuItem8ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem8ActionPerformed
        gc.suspendAll();
        jButton2.setEnabled( false );
        jMenuItem8.setEnabled( false );
        jButton3.setEnabled( true );
        jMenuItem9.setEnabled( true );
        busy = true;
    }//GEN-LAST:event_jMenuItem8ActionPerformed

    //When Popmenu Resume button is clicked
    private void jMenuItem9ActionPerformed( java.awt.event.ActionEvent evt )//GEN-FIRST:event_jMenuItem9ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem9ActionPerformed
        gc.resumeAll();
        jButton2.setEnabled( true );
        jMenuItem8.setEnabled( true );
        jButton3.setEnabled( false );
        jMenuItem9.setEnabled( false );
        busy = true;
    }//GEN-LAST:event_jMenuItem9ActionPerformed

    //When Popmenu Terminate button is clicked
    private void jMenuItem10ActionPerformed( java.awt.event.ActionEvent evt )//GEN-FIRST:event_jMenuItem10ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem10ActionPerformed
        gc.suspendAll();
        busy = false;
        long time = Long.parseLong( JOptionPane.showInputDialog( "Please specify delay of new Terminate event in milliseconds:" ) );
        Terminate te = new Terminate( gc, time );
        gc.eventList.add( te );
        gc.threadList.add( te.thread );
        gc.resumeAll();
        te.thread.start();
    }//GEN-LAST:event_jMenuItem10ActionPerformed

    /**
     * Method for closing the window. Confirms if BreenhouseControls is running
     */
    private void close()
    {
        if ( busy == true )
        {
            gc.suspendAll();
            int selectedOption = JOptionPane.showConfirmDialog( rootPane, "A Green house is still running! Confirm exit?", "Confirm", JOptionPane.YES_NO_OPTION );
            if ( selectedOption == JOptionPane.YES_OPTION )
            {
                gc.stopAll();
                if ( openWindows == 1 )
                {
                    System.exit( 0 );
                } else
                {
                    dispose();
                }
            } else
            {
                gc.resumeAll();
            }
        } else
        {
            dispose();
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main( String args[] )
    {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try
        {
            for ( javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels() )
            {
                if ( "Nimbus".equals( info.getName() ) )
                {
                    javax.swing.UIManager.setLookAndFeel( info.getClassName() );
                    break;


                }
            }
        } catch ( ClassNotFoundException ex )
        {
            java.util.logging.Logger.getLogger( GreenhouseControlsUI.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
        } catch ( InstantiationException ex )
        {
            java.util.logging.Logger.getLogger( GreenhouseControlsUI.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
        } catch ( IllegalAccessException ex )
        {
            java.util.logging.Logger.getLogger( GreenhouseControlsUI.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
        } catch ( javax.swing.UnsupportedLookAndFeelException ex )
        {
            java.util.logging.Logger.getLogger( GreenhouseControlsUI.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater( new Runnable()
        {
            public void run()
            {
                new GreenhouseControlsUI().setVisible( true );
            }
        } );
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    protected javax.swing.JButton jButton1;
    protected javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    protected javax.swing.JButton jButton4;
    protected javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    protected javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables
}
